
using IQIGame.Onigao.Framework;

namespace IQIGame.Onigao.Logic
{
    public class SkillCondition : IReusableClass
    {
        public int CheckFormula;
        public Skill skill { get; set; }
        public long truePart;
        public long falsePart;

        public void Initialize(Skill rParent, SkillConditionConfig rConfig)
        {
            this.skill = rParent;
            this.truePart = rConfig.truePart;
            this.falsePart = rConfig.falsePart;
        }

        private bool Check(object rParam)
        {
            return Formula.Calculate<bool>(this.CheckFormula, this.skill.executer, null);
        }

        public SkillPart GetExecute(object rResp)
        {
            if (this.skill != null)
            {
                var nUID = this.Check(rResp) ? this.truePart : this.falsePart;
                this.skill.partsDict.TryGetValue(nUID, out var rPart);
                return rPart;
            }

            return null;
        }

        public uint MaxStore => 5;
        public void OnReset()
        {
            this.CheckFormula = 0;
            this.truePart = 0;
            this.falsePart = 0;
        }
    }
}